package cn.wei.sdd.core.controller.admin;


import cn.wei.common.result.R;
import cn.wei.sdd.core.pojo.entity.BannerInfo;
import cn.wei.sdd.core.service.BannerInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Wei
 * @since 2021-10-07
 */
@Api(tags = "轮播图管理")
@RestController
@RequestMapping("/admin/core/bannerInfo")
public class AdminBannerInfoController {
    @Autowired
    private BannerInfoService bannerInfoService;

    @ApiOperation("轮播图分页列表")
    @GetMapping("/list/{page}/{limit}")
    public R listAll(@ApiParam(value = "page",required = true)
                     @PathVariable("page") Long page,
                     @ApiParam(value = "limit",required = true)
                     @PathVariable("limit") Long limit){
        Page<BannerInfo> pageParam = new Page<>(page,limit);
        IPage<BannerInfo> pageModel =  bannerInfoService.listPage(pageParam);
        return R.ok().data("pageModel", pageModel).message("获取列表成功");
    }

    @ApiOperation("轮播图列表")
    @GetMapping("/list")
    public R list(){

        List<BannerInfo> list =  bannerInfoService.listAll();
        return R.ok().data("list", list).message("获取列表成功");
    }




    @ApiOperation("添加轮播图")
    @PostMapping("addBannerInfo")
    public R addBannerInfo(@RequestBody BannerInfo bannerInfo){
        bannerInfoService.addBannerInfo(bannerInfo);
        return R.ok();
    }

    @ApiOperation("图片上架下架")
    @PutMapping("lock/{id}/{status}")
    public R Lock(
            @ApiParam(value = "图片id",required = true)
            @PathVariable Long id,
            @ApiParam(value = "状态（0：锁定 1：正常）",example = "0",required = true)
            @PathVariable Integer status){

        bannerInfoService.lock(id,status);
        return R.ok().message(status==1?"上架成功":"下架成功");

    }
}

